import java.net.*;
import java.io.*;
import java.util.Hashtable;

class AgentLoader extends ClassLoader
{
	AgentLoader(Socket socket)
		throws IOException 
	{
		this.socket = socket;
        DataInputStream din = new DataInputStream(socket.getInputStream());
        int size = din.readInt();
        bytecode=new byte[size];
        BufferedInputStream bin 
			= new BufferedInputStream(socket.getInputStream());
        if (bin.read(bytecode,0,size)!=size)
            System.out.println("Java is as stupid as posix");
        else
            System.out.println("Read "+size+" bytes of bytecode");
    }

    private byte[] loadClassData(String name)
	   	throws IOException 
	{
        return bytecode;
    }

    public synchronized Class loadClass(String name,boolean resolve)
    {
        Class c=null;

		try{
			byte[] data=loadClassData(name);
			int l=data.length;
			System.out.print("Define class ");
			if (name != null)
				System.out.print("\""+name+"\"");
			System.out.println("from "+ l +" bytes bytecode");
			c = defineClass(name, data, 0, l);
		}catch(Exception e){ }

        if (resolve)
            resolveClass(c);

        return c;
    }

    private Socket socket;
    private byte[] bytecode;
}
